package com.yaoyong.yy_demo.module.spring5.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class DemoPublisher {
    @Autowired
    ApplicationContext applicationContext;//注入ApplicationContext用来发布事件

    public void publish(String msg) {
        //使用publishEvent方法发布事件
        applicationContext.publishEvent(new DemoEvent(this,msg));
    }
}
